package com.view
{
	import flash.events.Event;
	
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	
	public class CarouselView extends BasicView
	{
		//Variables
		private var planeContainer:DisplayObject3D;
		private var plane:Plane;
		private var numPlanes:Number = 10;
		private var mat:ColorMaterial;
		
		//Constructor
		public function CarouselView()
		{
			super( 800, 600 );
			this.setCamera();
			this.createCarousel();
			this.initListeners();
		}
		
		//Public mehods
		
		//Private methods
		private function setCamera():void
		{
			camera.z = -200; 
			camera.y = 10; 
		}
		
		private function createCarousel():void
		{
			this.planeContainer = new DisplayObject3D();
			scene.addChild( this.planeContainer );
			
			this.mat = new ColorMaterial( );
			this.mat.doubleSided = true;
			
			for( var i:int = 0; i < this.numPlanes; i++ )
			{
				this.plane = new Plane( this.mat, 50, 50, 1, 1 );
				this.plane.name = "plane" + i;
				this.plane.pitch( ( 360 / this.numPlanes ) * i );
				this.plane.moveForward( 100 );
				this.planeContainer.addChild( this.plane );
			}
		}
		
		private function initListeners():void
		{
			this.addEventListener( Event.ENTER_FRAME, this.render );
		}
		
		//Event handlers
		private function render( $event:Event ):void
		{
			this.singleRender();
			this.planeContainer.pitch( viewport.containerSprite.mouseX*0.005  );
		}
	}
}